home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / doom / ldhe-src.0 / ldhe-src / dehacked / source / linux_text.cc < prev    next >
C/C++ Source or Header  |  1995-05-31  |  3KB  |  104 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5.  
  6. #include "dehacked.h"
  7. #include "linux_text.h"
  8.  
  9. // If you update this structure, be SURE you update the header. :)
  10. struct string_struct lnx_strings[LNX_NTEXTSEGS] = {
  11.     // Messages...
  12.     { 0x101A7,    (0x10566-0x101A7), NULL, 0 },
  13.     // More messages...
  14.     { 0xCDDB,    (0xCE60-0xCDDB), NULL, 0 },
  15.     // Even more messages...
  16.     { 0xD1A1,    (0xD214-0xD1A1), NULL, 0 },
  17.     // Level ending texts...
  18.     { 0x480,    (0x1223-0x480), NULL, 0 },
  19.     // Textures names...
  20.     { 0x1223,    (0x126C-0x1223), NULL, 0 },
  21.     // Monster names...
  22.     { 0x16F0,    (0x17B5-0x16F0), NULL, 0 },
  23.     // Command line options...
  24.     { 0x3293,    (0x35AB-0x3293), NULL, 0 },
  25.     // More command line options...
  26.     { 0x3664,    (0x3C3E-0x3664), NULL, 0 },
  27.     // Level names...
  28. /*    { 0x27E62,    (0x27F09-0x27E62), NULL, 0 }, */
  29.     { 0x25300,    (0x257d9-0x25300), NULL, 0 },
  30.     // Sprite names...  (in reverse order)
  31.     { 0x27AC4,    (0x27D76-0x27AC4), NULL, 0 },
  32.     // Sound names...  (in reverse order)
  33.     { 0x27F0F,    (0x281DA-0x27F0F), NULL, 0 },
  34.     // Cheat texts...
  35.     { 0x23A63,    (0x23B88-0x23A63), NULL, 0 },
  36. };
  37.  
  38. void lnx_loadtxt(char *buffer, int *len, int *nobjs, FILE *fp)
  39. {
  40.     char *o, *p;
  41.     int i, j, S;
  42.  
  43.     for ( *len=0, i=0; i<LNX_NTEXTSEGS; ++i ) {
  44.         fseek(fp, lnx_strings[i].offset, SEEK_SET);
  45.         fread((void *)buffer, lnx_strings[i].length, 1, fp);
  46.         for ( p=buffer, j=0, S=1; j<lnx_strings[i].length; ++j, ++p )
  47.         {
  48.             if ( ! *p ) 
  49.                 ++S;
  50.         }
  51.         lnx_strings[i].text = new char *[S];
  52.         for ( o=p=buffer, j=0, S=0; j<lnx_strings[i].length; ++j, ++p )
  53.         {
  54.             if ( ! *p ) {
  55.                 lnx_strings[i].text[S++] = o;
  56.                 o = p+1;
  57.             }
  58.         } 
  59.         lnx_strings[i].text[S] = NULL;
  60.         lnx_strings[i].nstrings = S;
  61.         *nobjs += S;
  62.         *len += lnx_strings[i].length;
  63.         buffer += lnx_strings[i].length;
  64.     }
  65. }
  66.  
  67. void lnx_writetxt(FILE *fp)
  68. {
  69.     int i;
  70.  
  71.     for ( i=0; i<LNX_NTEXTSEGS; ++i ) {
  72.         fseek(fp, lnx_strings[i].offset, SEEK_SET);
  73.         fwrite((void *)lnx_strings[i].text[0], 
  74.                         lnx_strings[i].length, 1, fp);
  75.     }
  76. }
  77.  
  78. void lnx_savetxt(char *textorigp, char *textdatap, int len, FILE *patchp)
  79. {
  80.     int i;
  81.  
  82.     for ( i=0; i<len; ++i ) {
  83.         if ( strcmp(textorigp+i, textdatap+i) != 0 ) {
  84.             fprintf(patchp, "\nText %d %d\n%s%s\n",
  85.     strlen(textdatap+i), strlen(textorigp+i), textdatap+i, textorigp+i);
  86.         }
  87.         while ( (i < len) && *(textdatap+i) ) ++i;
  88.     }
  89. }
  90.  
  91. EBool lnx_matchtxt(char *textdatap, int len, char *string, int *offset)
  92. {
  93.     int i;
  94.  
  95.     for ( i=0; i<len; ++i ) {
  96.         if ( strcmp(textdatap+i, string) == 0 ) {
  97.             *offset = i;
  98.             return YES;
  99.         }
  100.         while ( (i < len) && *(textdatap+i) ) ++i;
  101.     }
  102.     return NO;
  103. }
  104.